<?php

namespace app\admin\model\shopro\tokens;

use think\Model;


class Trade extends Model
{

    

    

    // 表名
    protected $name = 'shopro_tokens_trade';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
   /* protected $append = [
        'status_text'
    ];*/
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function sale()
    {
        return $this->belongsTo('app\admin\model\User', 'sale_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function buy()
    {
        return $this->belongsTo('app\admin\model\User', 'buy_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function whereBetweenTime($field, $startTime, $endTime)
    {
        return $this->where($field, '>=', $startTime)
            ->where($field, '<=', $endTime);
    }
}
